package service.Impl;

import Utils.ReflectUtils;
import Utils.db.pojo.Page;
import dao.TaskDAO;
import dao.impl.TaskDAOImpl;
import pojo.Task;
import service.TaskService;

import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;

/**
 * @author d11yu
 */
public class TaskServiceImpl implements TaskService {
    private TaskDAO taskDAO = new TaskDAOImpl();

    @Override
    public void addTask(Task task) {
        taskDAO.addTask(task);
    }

    @Override
    public void deleteTaskById(Integer id) {
        taskDAO.deleteTaskById(id);
    }

    @Override
    public void updateTaskById(Task task) {
        taskDAO.updateTaskById(task);
    }

    @Override
    public Task queryTaskById(Integer id) throws SQLException {
        return taskDAO.queryTaskById(id);
    }

    @Override
    public List<Task> queryAllTasks() throws SQLException {
        return taskDAO.queryAllTasks();
    }

    @Override
    public List<Task> queryAllTasksByUserId(Integer userId) throws SQLException {
        return taskDAO.queryAllTasksByUserId(userId);
    }

    @Override
    public List<Task> queryTasksByTasknameBlur(String taskname) throws SQLException {
        return taskDAO.queryTasksByTasknameBlur(taskname);
    }

    @Override
    public Page<Task> getPageByUserId(Integer pn, Integer ecp, String urlAction, Integer userId) throws SQLException, InvocationTargetException, IllegalAccessException {
        return Page.getPage(pn, ecp, urlAction, taskDAO, ReflectUtils.getMethod(taskDAO, "getEctByUserId", Integer.class), ReflectUtils.getMethod(taskDAO, "queryBeanListPerPageByUserId", Integer.class, Integer.class, Integer.class), userId);
    }

    @Override
    public Page<Task> getPageByTasknameBlurByUserId(Integer pn, Integer ecp, String urlAction, String taskname, Integer userId) throws SQLException, InvocationTargetException, IllegalAccessException {
        return Page.getPage(pn, ecp, urlAction, taskDAO, ReflectUtils.getMethod(taskDAO, "getEctTasknameBlurByUserId", String.class, Integer.class), ReflectUtils.getMethod(taskDAO, "queryBeanListPerPageTasknameBlurByUserId", Integer.class, Integer.class, String.class, Integer.class), taskname, userId);
    }

    /**
     * @param pn
     * @param ecp
     * @param urlAction
     * @return
     * @throws SQLException
     */
    @Override
    public Page<Task> getPage(Integer pn, Integer ecp, String urlAction) throws SQLException {
        return Page.getPage(pn, ecp, urlAction, taskDAO);
    }
}
